﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace SPMigrationOracleUtility
{
    public partial class view_mapping_lists : Form
    {
        public string mode;
        public string migMode;
        mapping_calss objMap = new mapping_calss();
               
        public int rowInd;
        public string FindMapVal;
        public string FindMapQry;
        public string FindMapTbl;

        public string SiteUrl;
        public view_mapping_lists()
        {
            
            InitializeComponent();
        }

         private void btnCancelViewMap_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void view_mapping_lists_Load(object sender, EventArgs e)
        {
            if (gvMappingLists.Rows.Count == 0)
            {
                btnMapDelete.Enabled = false;
            }

            else
            {
                btnMapDelete.Enabled = true;
            }
            
            SiteUrl = Convert.ToString(SPMigrationOracleUtility.Appl.Default.SiteURL);

            if (migMode == "Excel")
            {
                objMap.mapping_lists_Excel(gvMappingLists, SiteUrl,"Excel Migration"); 
            }
            else
            {
                objMap.mapping_lists_Excel(gvMappingLists, SiteUrl, "Oracle Migration");
                //objMap.mapping_lists(gvMappingLists, SiteUrl);
            }
           

            
            
            if (mode == "View")
            {
                btnMapEdit.Visible = false;
                btnMapEdit.Enabled = false;
                btnMapView.Visible = true;
                //btnMapView.Enabled = true;
            }
            else if (mode == "Edit")
            {
                btnMapEdit.Visible = true;
                // btnMapEdit.Enabled = true;
                btnMapView.Visible = false;
                btnMapView.Enabled = false;
            }
            else
            {
                 btnMapDelete.Visible = true;
                 btnMapEdit.Visible = false;
                 btnMapView.Visible = false;
               // btnMapView.Enabled = false;
            }

        }

        public void Enable(string view_edit)
        {
            mode = view_edit ;
        }

        public void MigrationMode(string migrationMode)
        {
            migMode = migrationMode;
        }

        private void gvMappingLists_MouseClick(object sender, MouseEventArgs e)
        {
            
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
               if (gvMappingLists.Rows.Count > 0)
                {
                    rowInd = gvMappingLists.Rows.IndexOf(gvMappingLists.CurrentRow);
                    FindMapQry = Convert.ToString(gvMappingLists.Rows[rowInd].Cells[3].Value);
                    FindMapTbl = Convert.ToString(gvMappingLists.Rows[rowInd].Cells[4].Value);
                    FindMapVal = Convert.ToString(gvMappingLists.Rows[rowInd].Cells[5].Value);
                    //contextMenuStrip1.Show(Cursor.Position);
                    if (mode == "View")
                    {
                        btnMapView.Enabled = true;
                        
                    }
                    if (mode == "Delete")
                    {
                        btnMapDelete.Enabled = true;

                    }
                    else
                    {
                        btnMapEdit.Enabled = true;
                       
                    }
                  
                }
                else
                {
                    btnMapEdit.Enabled = true;
                }
                    
            }
           
        }

        private void btnMapEdit_Click(object sender, EventArgs e)
        {
            if (migMode == "Excel")
            {
                ExcelSPmigrationManipulate objWiz = new ExcelSPmigrationManipulate();
                this.Hide();
                objWiz.mapid = FindMapVal;
                objWiz.mode = mode;
                objWiz.Show();
            }
            else
            {
                EditMapplingForm objWiz = new EditMapplingForm();
                this.Hide();
                objWiz.mapid = FindMapVal;
                objWiz.mode = mode;
                objWiz.Show();
            }
        }

        private void btnMapView_Click(object sender, EventArgs e)
        {
            if (migMode == "Excel")
            {
                ExcelSPmigrationManipulate objWiz = new ExcelSPmigrationManipulate();
                this.Hide();
                mode = "View";
                objWiz.mapid = FindMapVal;
                objWiz.mode = mode;
                objWiz.Show();
            }
            else
            {

                EditMapplingForm objWiz = new EditMapplingForm();
                //objMap.Mapping_Col_List_Retrieve(FindMapVal);
                this.Hide();
                mode = "View";
                objWiz.mapid = FindMapVal;
                objWiz.mode = mode;
                objWiz.Show();
            }

        }

        private void btnMapDelete_Click(object sender, EventArgs e)
        {

            DialogResult result = MessageBox.Show("Are you sure to delete the Mapping Record ?", "Delete Selection Mapping Record", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
            {
                objMap.Mapping_Delete(FindMapVal);
                //objMap.mapping_lists(gvMappingLists, SiteUrl);
                //objMap.mapping_lists_Excel(gvMappingLists, SiteUrl, migMode);
                MessageBox.Show("Mapping Record Deleted");
                if (migMode == "Excel")
                {
                    objMap.mapping_lists_Excel(gvMappingLists, SiteUrl, "Excel Migration");
                }
                else
                {
                    objMap.mapping_lists_Excel(gvMappingLists, SiteUrl, "Oracle Migration");
                    //objMap.mapping_lists(gvMappingLists, SiteUrl);
                }
                if (gvMappingLists.Rows.Count == 0)
                {
                    btnMapDelete.Enabled = false;
                }
                
            }

            else
            {
                this.Close();
            }
                 
        }

    }
}
